<template>
  <div>
    <el-row>
      <el-col :span="(readWord === 'edit' && !isDelete) ? 20 : 24">
        <div class="inputBox">
          <el-input :readonly="true" v-model="FormData.projectName"></el-input>
          <ul class="fileBar" v-if="FormData.wordFile">
            <li @click="openWord('view')"><i class="el-icon-search"></i></li>
            <li v-if="readWord === 'edit'" @click="openWord('edit')"><i class="el-icon-edit"></i></li>
            <li @click="downWord"><i class="el-icon-download"></i></li>
<!--            <li v-if="isDelete && readWord === 'edit'" @click="beforeRemove"><i class="el-icon-delete"></i></li>-->
          </ul>
        </div>
      </el-col>
      <el-col :span="1" v-if="readWord === 'edit' && !isDelete">
        <el-button @click="getWord">点击生成</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {genApplyWord} from "@/api/adis/project/projectApply";
import {genNoticeWord} from "@/api/adis/project/notice";
import {genWord as genReportOpinionWord } from "@/api/adis/report/reportOpinion"
import {genWord as genReportDraftWord } from "@/api/adis/report/reportDraft"
import {genWord as genReportFinalWord} from "@/api/adis/report/reportFinal"
import {genEvidenceWord,genEngineeringWord} from "@/api/adis/execute/evidence";
import {genWord as genReportAdviceWord} from "@/api/adis/report/advice";
import {genWord as genWorksheetWord} from "@/api/adis/execute/paper";
import {genProjectWord} from "@/api/adis/project/project";
import {genRectifyNoticeWord} from "@/api/adis/track/rectify";
import {genRectifyReportWord} from "@/api/adis/track/rectifyReprot";

export default {
    props: {
      FormData: {
        type: Object,
        default() {
          return null
        }
      }, // 数据，必填
      readWord: {
        type: String,
        default: 'view'
      }, // view:只查看，edit:查看编辑下载
      isDelete: {
        type: Boolean,
        default: false
      },
      pageType: {
        type: String,
        required: true
      } // 页面类型，必填
    },
    data() {
      return {

      }
    },
    methods: {
      getWord() {
        let api;
        switch (this.pageType){
          case 'worksheet':
            api = genWorksheetWord;
            break;
          case 'engineeringEvidence':
            api = genEngineeringWord;
            break;
          case 'rectifyReport':
            api = genRectifyReportWord;
            break;
          case 'rectifyNotice':
            api = genRectifyNoticeWord;
            break;
          case 'reportAdvice':
            api = genReportAdviceWord;
            break;
          case 'evidence':
            api = genEvidenceWord;
            break;
          case 'report':
            api = genReportFinalWord;
            break;
          case 'reportOpinion':
            api = genReportOpinionWord;
            break;
          case 'reportDraft':
            api = genReportDraftWord;
            break;
          case 'project':
            api = genProjectWord;
            break;
          case 'projectApply':
            api = genApplyWord;
            break;
          case 'projectNotice':
            api = genNoticeWord;
            this.FormData.updateTime=''
            break;
          default:
            this.$message({
              type: "error",
              message: "未知的页面类型!"
            });
            break;
        }
        api(this.FormData).then((res) => {
          let data = res.data.data;
          console.log(data);
          if(data.message) {
            this.$message({
              type: "error",
              message: data.message
            });
          } else {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          }
          this.$emit("createWordFile", data)
        }, () => {});
      },
      openWord(type) {
        if(!this.FormData.wordFile) {
          this.$message({
            type: "error",
            message: "请先生成文书!"
          });
          return;
        }
        if(this.FormData.wordFile.indexOf('http') < 0) {
          this.$message({
            type: "error",
            message: "请重新生成文书!"
          });
          return;
        }
        const { href } = this.$router.resolve({
          path: '/webOffice',
          query: {
            url: this.FormData.wordFile,
            type: type
          }
        });
        window.open(href, '_blank');
      },
      downWord() {
        const a = document.createElement('a');
        let url = this.FormData.wordFile;
        a.setAttribute('download', '');
        a.setAttribute('href', url);
        a.click();
      },
      beforeRemove(file) {
        this.$confirm('确认删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.$emit("createWordFile")
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
      },
    }
	}
</script>

<style lang="scss" scoped>
  .arrbox {
    width: 100%;
    display: inline-block;
  }
  .check-select{
    ::v-deep.hide-popper{
      display: none;
    }
  }
  .userBox {
    width: 20px;
    height: 100%;
    position: absolute;
    z-index: 2;
    top: 6px;
    right: 0;
  }
  .el-icon-user, .el-icon-postcard, .el-icon-office-building, .el-icon-guide {
    font-size: 20px;
    color: #409EFF;
    cursor: pointer;
  }
  ::v-deep .el-input__suffix{
    i:not(.el-select__caret){
      display: none;
    }
  }
  .selectMain {
    width: 100%;
    height: 100%;
  .seachButton{
    width: 100%;
    align-items: center;
    display: flex;
    div.btn{
      width: 25%;
      max-width: 70px;
      max-width: 80px;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 12px;
      color: #fff;
      background-color: #409EFF;
      border-radius: 5px;
      cursor: pointer;
    }
  }
  .selectDiv{
    width: 100%;
    max-width: 500px;
    margin-top: 10px;
    padding:  0 10px 0 0;
    .list{
      width: 100%;
      padding: 10px 20px 10px 10px;
      color: #666;
      cursor: pointer;
      position: relative;
      &.selected{
        color: #409EFF;
        &::after{
          position: absolute;
          right: 0px;
          top: 50%;
          transform: translateY(-50%);
          font-family: element-icons;
          content: "\e6da";
          font-size: 12px;
          font-weight: 700;
          -webkit-font-smoothing: antialiased;
        }
      }
    }
    .selectDivAuto{
      width: calc(100% + 15px);
      max-height: 300px;
      overflow-y: auto;
      .list{
        padding: 10px 30px 10px 10px;
        &.selected::after{
          right: 10px;
        }
      }
    }
  }
  }
  .allCheck{
    border-bottom: 1px solid rgb(228, 225, 225);
  }
</style>
